home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
11587
/
11587.xpi
/
chrome
/
aviary.jar
/
content
/
pearlutil-clipboard.js
< prev
next >
Wrap
Text File
|
2009-05-12
|
3KB
|
91 lines
/* Copyright (c) 2006-2009 Pearl Crescent, LLC. All Rights Reserved. */
/* vim: set sw=2 sts=2 ts=8 et syntax=javascript: */
if (!com) var com = {};
if (!com.aviary) com.aviary = {};
if (!com.aviary.talon) com.aviary.talon = {};
if (!com.aviary.talon.clipboard) com.aviary.talon.clipboard =
{
CopyDataURIToClipboard: function(aDataURI, aCompletionFunc)
{
var _this = this;
var imageContainer = null;
function notifyCompletion(aDidSucceed)
{
if (imageContainer)
{
imageContainer.parentNode.removeChild(imageContainer);
imageContainer = null;
}
if (aCompletionFunc)
aCompletionFunc(aDidSucceed);
}
function createImageForCopy()
{
var navbar = document.getElementById("nav-bar");
if (!navbar)
return null;
const kXULNameSpace = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const kHTMLNameSpace = "http://www.w3.org/1999/xhtml";
var sbElem = document.createElementNS(kXULNameSpace, "scrollbox");
sbElem.setAttribute("width", 1);
sbElem.setAttribute("height", 1);
var imgElem = document.createElementNS(kHTMLNameSpace, "img");
imgElem.setAttribute("style", "display:none");
sbElem.appendChild(imgElem);
navbar.appendChild(sbElem);
imageContainer = sbElem;
return imgElem;
}
try
{
var imgElem = createImageForCopy();
if (!aDataURI || !imgElem)
{
notifyCompletion(false);
return;
}
function onImageLoad()
{
var tmpNode = document.popupNode;
document.popupNode = imgElem;
goDoCommand("cmd_copyImageContents");
document.popupNode = tmpNode;
cleanupImageForCopy();
notifyCompletion(true);
}
function onImageError()
{
cleanupImageForCopy();
notifyCompletion(false);
}
function cleanupImageForCopy()
{
imgElem.removeEventListener("load", onImageLoad, false);
imgElem.removeEventListener("error", onImageError, false);
imgElem.removeAttribute("src");
}
imgElem.QueryInterface(Components.interfaces.nsIImageLoadingContent);
imgElem.addEventListener("load", onImageLoad, false);
imgElem.addEventListener("error", onImageError, false);
imgElem.setAttribute("src", aDataURI);
// NOTE: onImageLoad() or onImageError() will report status.
}
catch (e)
{
notifyCompletion(false);
}
}, // CopyDataURIToClipboard
endOfObject: true
}; // com.aviary.talon.clipboard